# -*- coding: utf-8 -*-

import stomp,sys

class MessageSender(stomp.ConnectionListener):
    def __init__(self, message_count):
        self.count = message_count
        self.conn = stomp.Connection([('localhost',61613,)])
        self.conn.add_listener(self)

    def on_connecting(self,host_and_port):
        print 'logging in'
        self.conn.connect()

    def on_connected(self,headers,body):
        print 'connected'
        for i in xrange(self.count):
            print 'Sending Message #%d' % i
            self.conn.send('Message #%d' % i,destination='/queue/python2')

        print 'Done'

    def send_messages(self):
        self.conn.start()

def help():
    print 'Usage: python send.py <number of messages>'

if __name__ == '__main__':
    if len(sys.argv)-1 == 0:
        help()
    else:
        MessageSender(int(sys.argv[1])).send_messages()
        raw_input('Press ENTER when done\n') 
